import { createContext, useContext } from 'react'
import type { CheckboxValue } from './type'

type CheckboxGroupContextTypeType = {
  /** 选中值集合 */
  value: CheckboxValue[]
  /** 整组禁用 */
  disabled: boolean
  /** 选中时触发 */
  check: (val: CheckboxValue) => void
  /** 未选中时触发 */
  uncheck: (val: CheckboxValue) => void
}

const CheckboxGroupContext = createContext<CheckboxGroupContextTypeType | null>(null)

export const CheckboxGroupProvider = CheckboxGroupContext.Provider

export const useCheckboxGroup = (): CheckboxGroupContextTypeType | null => useContext(CheckboxGroupContext)
